﻿Imports Microsoft.VisualBasic
Imports System.Data

<System.ComponentModel.DataObjectAttribute(True)> _
Public Class BLL_AddTrainingCourse

    Public Sub New()
        ' 
        ' TODO: 在此加入建構函式的程式碼 
        ' 
    End Sub

    'SELECT 
    <System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.[Select])> _
    Public Function BLL_Select(ByVal Id As Integer) As DataTable

        Dim sql As New MyStringBuilder
        Dim dat As New clsData

        sql.AppendFormat("SELECT * ")
        sql.AppendFormat("FROM TrainingCourse ")
        sql.AppendFormat(String.Format("WHERE id={0}", Id))
        Return dat.GetData(sql)

    End Function

    'Insert
    <System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Insert)> _
    Public Function BLL_Insert(ByVal CourseName As String, ByVal CourseType As String, ByVal TeacherEmail As String, ByVal TeacherName As String, ByVal TeacherTEL As String, ByVal Org As String, ByVal Hour As Integer, ByVal ClassDetail As String) As Integer
        Dim dat As New clsData
        Dim sql As New MyStringBuilder

        Using scope As New Transactions.TransactionScope

            sql.Length = 0
            sql.AppendFormat("insert TrainingCourse (CourseName,CourseType,TeacherEmail,TeacherName,TeacherTEL,Org,Hour,ClassDetail) select ")
            sql.AppendFormat(" '{0}' ", CourseName)
            sql.AppendFormat(",'{0}' ", CourseType)
            sql.AppendFormat(",'{0}' ", TeacherEmail)
            sql.AppendFormat(",'{0}' ", TeacherName)
            sql.AppendFormat(",'{0}' ", TeacherTEL)
            sql.AppendFormat(",'{0}' ", Org)
            sql.AppendFormat(",{0} ", Hour)
            sql.AppendFormat(",'{0}' ", ClassDetail)

            dat.AccData(sql)
            scope.Complete()

            Return 1

        End Using

    End Function

    'Update 
    <System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Update)> _
       Public Function BLL_Update(ByVal CourseName As String, ByVal CourseType As String, ByVal TeacherEmail As String, ByVal TeacherName As String, ByVal TeacherTEL As String, ByVal Org As String, ByVal Hour As Integer, ByVal ClassDetail As String, ByVal original_Id As Integer) As Integer
        Dim dat As New clsData
        Dim sql As New MyStringBuilder

        Using scope As New Transactions.TransactionScope

            sql.AppendFormat("UPDATE TrainingCourse ")
            sql.AppendFormat("SET CourseName='{0}' ", CourseName)
            sql.AppendFormat(",CourseType='{0}'", CourseType)
            sql.AppendFormat(",TeacherEmail='{0}'", TeacherEmail)
            sql.AppendFormat(",TeacherName='{0}'", TeacherName)
            sql.AppendFormat(",TeacherTEL='{0}'", TeacherTEL)
            sql.AppendFormat(",Org='{0}'", Org)
            sql.AppendFormat(",Hour={0}", Hour)
            sql.AppendFormat(",ClassDetail='{0}'", ClassDetail)
            sql.AppendFormat("WHERE Id={0}; ", original_Id)

            dat.AccData(sql)
            scope.Complete()

            Return 1

        End Using

    End Function

End Class
